package com.gzsxy.esjy.gateway.config.properties;

import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @author xiaolong
 * @version 1.0
 * @description: 网关配置
 * @date 2021/12/28 8:50
 */
@Setter
@Getter
@RefreshScope
@Configuration
@ConfigurationProperties(prefix = GateWayProperties.PREFIX)
public class GateWayProperties {

    public final static String PREFIX = "esjy.gateway";

    /**
     * 后台排除检验
     */
    @Value("#{'${esjy.gateway.excluteAuthPaths:}'.split(',')}")
    private List<String> excluteAuthPaths;

    /**
     * 前台排除检验
     */
    @Value("#{'${esjy.gateway.apiExcluteAuthPaths:}'.split(',')}")
    private List<String> apiExcluteAuthPaths;

    /**
     * 权限
     */
    private AuthProperties auth = new AuthProperties();

    /**
     * 日志
     */
    private LogProperties log = new LogProperties();

    @Getter
    @Setter
    public static class AuthProperties{

        /**
         * token 刷新预留时间:分钟 reserveMinute > floatMinute >=1, 默认5
         */
        private int reserveMinute = 5;

        /**
         * 浮动时间
         */
        private int floatMinute = 1;
    }


    @Getter
    @Setter
    public static class LogProperties {

        /**
         * 消耗时间日志开启
         */
        private boolean consuTime = true;

        /**
         * 请求日志
         */
        private Log request = new Log();

        /**
         * 响应日志
         */
        private Log response = new Log();


        @Setter
        @Getter
        public static class Log{

            /**
             * 是否开启
             */
            private boolean enabled = true;

            /**
             * 包含
             */
            private String paths = "/**";

            /**
             * 报文上限
             */
            private int maxBody = 1024*1024*10;

            /**
             * 报文内容
             */
            private String contentTypes = "application/json,application/x-www-form-urlencoded";
        }

    }
}
